package demo.practice.stack;

import java.util.Stack;

public class P155 {
    class MinStack {

        Stack<Integer> data;
        Stack<Integer> min;

        /** initialize your data structure here. */
        public MinStack() {
            data= new Stack<>();
            min= new Stack<>();
        }

        public void push(int x) {
            data.push(x);
            if(min.size()==0 || x<=min.peek())
                min.push(x);
        }

        public void pop() {
            if(data.peek().equals(min.peek()))
                min.pop();
            data.pop();
        }

        public int top() {
            if(data.size()==0)
                return -1;
            else
                return data.peek();
        }

        public int getMin() {
            if(data.size()==0)
                return -1;
            else
                return min.peek();
        }
    }

}
